import os


import paramiko
import traceback

from paramiko.rsakey import RSAKey
from io import StringIO

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname='10.0.0.88', port=22, username='root', password='123456', timeout=10)  # 1. 直接密码远程连接的方式
# ssh.connect(hostname='39.102.132.191', port=22, username='root', pkey=pkey, timeout=10)  #2. 使用秘钥免密登录的方式
cli = ssh.get_transport().open_session() # 开启会话，持续发送指令
cli.settimeout(20) # 20s内没有交互了，会自动断开连接
# cli.exec_command('ifconfig')
cli.exec_command('ls')
stdout = cli.makefile("rb", -1)
content = stdout.read().decode()

print(content)

# result = stdout.read()
# print(ret)
ssh.close()


